In [1]:
import pandas as pd
In [2]:
import pulp as opt
In [15]:
df = pd.read_csv('data_movies_week_9.csv', header = None)
In [16]:
df
Out[16]:
In [17]:
x1 = opt.LpVariable('x1',0,8, cat = 'Integer')
x2 = opt.LpVariable('x2',0,8, cat = 'Integer')
x3 = opt.LpVariable('x3',0,8, cat = 'Integer')
x4 = opt.LpVariable('x4',0,8, cat = 'Integer')
x5 = opt.LpVariable('x5',0,8, cat = 'Integer')
x6 = opt.LpVariable('x6',0,8, cat = 'Integer')
x7 = opt.LpVariable('x7',0,8, cat = 'Integer')
x8 = opt.LpVariable('x8',0,8, cat = 'Integer')
x9 = opt.LpVariable('x9',0,8, cat = 'Integer')
x10 = opt.LpVariable('x10',0,8, cat = 'Integer')
x11 = opt.LpVariable('x11',0,8, cat = 'Integer')
x12 = opt.LpVariable('x12',0,8, cat = 'Integer')
x13 = opt.LpVariable('x13',0,8, cat = 'Integer')
x14 = opt.LpVariable('x14',0,8, cat = 'Integer')
x15 = opt.LpVariable('x15',0,8, cat = 'Integer')
x16 = opt.LpVariable('x16',0,8, cat = 'Integer')
In [18]:
prob = opt.LpProblem('Optimize_FML_Success',opt.LpMaximize)
In [19]:
prob += df.ix[0,2]*x1 + df.ix[1,2]*x2 + df.ix[2,2]*x3 + df.ix[3,2]*x4 + df.ix[4,2]*x5 + df.ix[5,2]*x6 + df.ix[6,2]*x7 + df.ix[7,2]*x8 + df.ix[8,2]*x9 + df.ix[9,2]*x10 + df.ix[10,2]*x11 + df.ix[11,2]*x12 + df.ix[12,2]*x13 + df.ix[13,2]*x14 + df.ix[14,2]*x15 + df.ix[15,2]*x16
In [20]:
prob
Out[20]:
In [21]:
prob += x1+x2+x3+x4+x5+x6+x7+x8+x9+x10+x11+x12+x13+x14+x15+x16 <= 8
In [22]:
prob += x1+x2+x3+x4+x5+x6+x7+x8+x9+x10+x11+x12+x13+x14+x15+x16 >= 8
In [23]:
prob += df.ix[0,3]*x1 + df.ix[1,3]*x2 + df.ix[2,3]*x3 + df.ix[3,3]*x4 + df.ix[4,3]*x5 + df.ix[5,3]*x6 + df.ix[6,3]*x7 + df.ix[7,3]*x8 + df.ix[8,3]*x9 + df.ix[9,3]*x10 + df.ix[10,3]*x11 + df.ix[11,3]*x12 + df.ix[12,3]*x13 + df.ix[13,3]*x14 + df.ix[14,3]*x15 + df.ix[15,3]*x16 <= 1000
In [24]:
opt.pulpTestAll()
In [25]:
status = prob.solve(opt.PULP_CBC_CMD(msg=0))
In [26]:
opt.LpStatus[status]
Out[26]:
In [27]:
for v in prob.variables():
print (v.name, "=" , v.varValue)
In [28]:
opt.value(prob.objective)
Out[28]:
In [ ]: